package com.ruoyi.web.controller.company;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demand.domain.Demand;
import com.ruoyi.demand.service.IDemandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线留言Controller
 *
 * @author ruoyi
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/demand/demand")
public class DemandController extends BaseController
{
    @Autowired
    private IDemandService demandService;

    /**
     * 查询在线留言列表
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demand demand)
    {
        startPage();
        List<Demand> list = demandService.selectDemandList(demand);
        return getDataTable(list);
    }

    /**
     * 导出在线留言列表
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:export')")
    @Log(title = "在线留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Demand demand)
    {
        List<Demand> list = demandService.selectDemandList(demand);
        ExcelUtil<Demand> util = new ExcelUtil<Demand>(Demand.class);
        util.exportExcel(response, list, "在线留言数据");
    }

    /**
     * 获取在线留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(demandService.selectDemandById(id));
    }

    /**
     * 新增在线留言
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:add')")
    @Log(title = "在线留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demand demand)
    {
        return toAjax(demandService.insertDemand(demand));
    }

    /**
     * 修改在线留言
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:edit')")
    @Log(title = "在线留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demand demand)
    {
        return toAjax(demandService.updateDemand(demand));
    }

    /**
     * 删除在线留言
     */
    @PreAuthorize("@ss.hasPermi('demand:demand:remove')")
    @Log(title = "在线留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(demandService.deleteDemandByIds(ids));
    }
}

